abstract class FootStepListener {
  void step(StepType stepType, KeyType keyType, Position position) {}
}

class StepAdapter {
  // final double FOOT_CENTER_UPDATE_MIN_DIS_X = 0.3;
  static const double STEP_IS_VERTICAL = 0.1;
  static const double RECT_WH = 0.2;
  var center = Position(0.5, 0.8);
  double scale = 1;
  // double rect_wh = RECT_WH;
  List<StepPosition> steps = [];

  StepAdapter() {
    _updatePosition();
  }

  //当两脚距离大于某个值的时候计算中心点?
  void update(leftHip, rightHip, leftShoulder , rightShoulder) {
    if (leftHip.x > 1 || leftHip.y > 1) {
      return;
    }
    scale = leftHip.y - leftShoulder.y;
    // rect_wh = StepAdapter.RECT_WH*scale*4;
    //臀部位置加上身体长度乘以脚的比例
    center =
        Position(0.5, (leftHip.y + rightHip.y)/2  + scale*1.25);
    _updatePosition();
  }

  _updatePosition() {
    steps = [
      //0.3, 0.85
      StepPosition(center.x - 0.7*scale , center.y)..stepType = StepType.left,
      //0.5, 0.75
      StepPosition(center.x, center.y - 0.2*scale )..stepType = StepType.down,
      //0.5, 0.95
      StepPosition(center.x, center.y + 0.2*scale )..stepType = StepType.up,
      //0.7, 0.85
      StepPosition(center.x + 0.7 *scale , center.y)..stepType = StepType.right,
    ];
  }
}

class StepPosition extends Position {
  StepType stepType = StepType.unknown;

  StepPosition(super.x, super.y);
}

class Position {
  double _x = 0;
  double _y = 0;

  Position(double x, double y) {
    _x = x;
    _y = y;
  }

  double get x => _x;

  double get y => _y;
}

enum KeyType { keydown, keyup, unknown }

enum StepType { left, down, up, right, unknown }

abstract class FootStep {
  void setStepListener(FootStepListener listener) {}

  void setStepAdapter(StepAdapter stepAdapter) {}

  void update(Position footPosition) {}
}
